package Util;

import org.json.JSONException;
import org.json.JSONObject;
import th.co.tac.esv.tel.ejb.dat.tpt.OutputTemplate;

/**
 *
 * @author Peat
 */
public class ServiceResponseObject {

    private int errorStatus;
    private String errorCode;
    private String errorMsg;
    private String errorTuxMsgSqlCode;
    private String errorTuxMsgTextEng;
    private String errorTuxMsgTextThai;

    private OutputTemplate sourceObject;

    public ServiceResponseObject(int errorStatus, String errorCode,
            String errorMsg, String errorTuxMsgSqlCode, String errorTuxMsgTextEng,
            String errorTuxMsgTextThai, OutputTemplate sourceObject) {
        this.errorStatus = errorStatus;
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
        this.errorTuxMsgSqlCode = errorTuxMsgSqlCode;
        this.errorTuxMsgTextEng = errorTuxMsgTextEng;
        this.errorTuxMsgTextThai = errorTuxMsgTextThai;
        this.sourceObject = sourceObject;
    }

    public boolean getResult() {
        return errorStatus == 0;
    }

    public int getErrorStatus() {
        return errorStatus;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public String getErrorTuxMsgSqlCode() {
        return errorTuxMsgSqlCode;
    }

    public String getErrorTuxMsgTextEng() {
        return errorTuxMsgTextEng;
    }

    public String getErrorTuxMsgTextThai() {
        return errorTuxMsgTextThai;
    }

    public OutputTemplate getSourceObject() {
        return sourceObject;
    }

    public JSONObject toJSON() throws JSONException {
        JSONObject result = new JSONObject();
        result.put("result", getResult());
        // 0 OK, -1 SERVER ERROR, -2 BL ERROR
        result.put("errorStatus", getErrorStatus());
        result.put("errorCode", getErrorCode());
        result.put("errorMsg", TranslatorUtils.oneEscape(getErrorMsg()));
        result.put("errorTuxMsgSqlCode", getErrorTuxMsgSqlCode());
        result.put("errorTuxMsgTextEng", TranslatorUtils.oneEscape(getErrorTuxMsgTextEng()));
        result.put("errorTuxMsgTextThai", TranslatorUtils.oneEscape(getErrorTuxMsgTextThai()));
        return result;
    }
}
